package com.masterrabbit.mcslf.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.masterrabbit.common.core.web.domain.AjaxResult;
import com.masterrabbit.mcslf.mapper.FinancialRecordsMapper;
import com.masterrabbit.mcslf.pojo.FinancialRecords;
import com.masterrabbit.mcslf.service.FinancialRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

@RestController
@RequestMapping("/FR")
public class FRController {
    @Autowired
    FinancialRecordsService financialRecordsService;
    @Autowired
    FinancialRecordsMapper financialRecordsMapper;
    @RequestMapping("/list")
    public AjaxResult getlist(HttpServletRequest request, @RequestBody HashMap<String,Object> map){
        String currentStore = request.getHeader("currentStore");
        IPage<FinancialRecords> page = new Page<>((Integer)map.get("current"),(Integer)map.get("size"));
        QueryWrapper<FinancialRecords> financialRecordsQueryWrapper = new QueryWrapper<>();
        financialRecordsQueryWrapper.lambda().eq(FinancialRecords::getMerchantId,currentStore);
        if (map.get("date")!=null){
            financialRecordsQueryWrapper .lambda().like(FinancialRecords::getCreateTime,map.get("date"));
        }
        if (map.get("type")!=null){
            financialRecordsQueryWrapper .lambda().like(FinancialRecords::getChangeType,map.get("type"));
        }
        IPage<FinancialRecords> page1 = financialRecordsMapper.selectPage(page, financialRecordsQueryWrapper);
        return AjaxResult.success(page1);
    }
}
